include "icon1bit.inc"
include "icon4bit.inc"
include "icon8bit.inc"
include "icon32bit.inc"

proc draw_icon_32x32,x,y
   pusha
   pusha
   mov ax,[bmp+head.size+ientry.size+infoheader.BitDepth]
   cmp ax,4
   je .img4bpp
   cmp ax,8
   je .img8bpp

   ; Convert 1bpp-image to raw-image
   mov esi,bmp+head.size+ientry.size+infoheader.size+((32*32)*4)
   mov edi,raw2
   call conv1bpp32_32x32
   popa
   mov esi,bmp+head.size+ientry.size+infoheader.size
   mov edi,raw2
   jmp .draw

.img8bpp:
   ; Convert 4bpp-image to raw-image
   mov esi,bmp+head.size+ientry.size+infoheader.size+1024
   mov edi,raw
   call conv8bpp_32x32

   ; Convert 1bpp-image to raw-image
   mov esi,bmp+head.size+ientry.size+infoheader.size+1024+(32*32)
   mov edi,raw2
   call conv1bpp8_32x32
   popa

   mov esi,raw
   mov edi,raw2
   jmp .draw

.img4bpp:
   ; Convert 4bpp-image to raw-image
   mov esi,bmp+head.size+ientry.size+infoheader.size+64
   mov edi,raw
   call conv4bpp_32x32

   ; Convert 1bpp-image to raw-image
   mov esi,bmp+head.size+ientry.size+infoheader.size+64+(32*16)
   mov edi,raw2
   call conv1bpp4_32x32
   popa


   mov esi,raw
   mov edi,raw2
.draw:
;   add esi,(32+32)*4
   mov eax,[x]
   mov [icon_x],eax
   mov eax,[y]
   add eax,32
   mov [icon_y],eax
.nxt:
   push edi
   mov edi,[edi]
   cmp edi,0
   jne .no_put_pixel
   and esi,0xFFFFFF
   invoke PutPixel,dword [icon_x],dword [icon_y],dword [esi]
.no_put_pixel:
   pop edi
   add esi,4
   add edi,4
   inc [icon_x]
   mov eax,[x]
   add eax,32
   cmp [icon_x],eax
   jne .nxt
   dec [icon_y]
   mov eax,[x]
   mov [icon_x],eax
   mov eax,[y]
   cmp [icon_y],eax
   jne .nxt
   popa
   ret
endp
